import java.text.*;
import java.util.*;
import java.io.*;

class SecondOrderPosteriorProb {

  SecondOrderForward fwd;

  SecondOrderBackward bwd;

  private double logprob;

  SecondOrderPosteriorProb(SecondOrderForward fwd, SecondOrderBackward bwd) {
    this.fwd = fwd; 
    this.bwd = bwd;
    logprob = fwd.logprob();
  }

  double posterior(int i, int k) { return Math.exp(fwd.f[i][k] + bwd.b[i][k] - logprob); }

}
